concatenate object Text with rtf

Hello,

I'm trying to concatenate Object Text of several objects . But i want to keep the rtf formating of each objects. I didn't sucess. What i done is concatenating rtf extracted from each object wich didn't work because i repeat the rtf heading like this simple exemple:

{\rtf1\ansi\ansicpg1252\deff0\deflang1036{\fonttbl{\f0\fnil\fcharset0 Tahoma;}{\f1\fnil\fcharset2 Symbol;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 ligne 1\par
\pard{\pntext\f1\'B7\tab}{\*\pn\pnlvlblt\pnf1\pnindent0{\pntxtb\'B7}}ligne2\par
}
{\rtf1\ansi\ansicpg1252\deff0\deflang1036{\fonttbl{\f0\fnil\fcharset0 Tahoma;}{\f1\fnil\fcharset2 Symbol;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 ligne 1\par
\pard{\pntext\f1\'B7\tab}{\*\pn\pnlvlblt\pnf1\pnindent0{\pntxtb\'B7}}ligne2\par
}

Someone have a solution?

Thanks,
thomas.abdoul - Wed Sep 12 05:46:26 EDT 2012

Re: concatenate object Text with rtf
Mathias Mamsch - Wed Sep 12 05:55:07 EDT 2012

The funny thing is, that DOORS will actually allow you to do that (i.e. just concatenate the richText, write that to an attribute or display it) and still show a valid result. So it should be fine, if you just concat the richTexts and write them back to the object. If you want valid RTF then you would need to use richTextFragment, to cut off the header, BUT this will also cut away the font table. So to make a function that would give you a valid richText, you would need to create a new font table from the concatenated richTexts and translate the font statements in one of the richText. Total overkill, so I would suggest you stay with the concatenated richTexts.

There are several examples in the forum for concatenating richText. Use the search to find code examples. Hope this helps, regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: concatenate object Text with rtf
thomas.abdoul - Wed Sep 12 09:20:39 EDT 2012

Mathias Mamsch - Wed Sep 12 05:55:07 EDT 2012
The funny thing is, that DOORS will actually allow you to do that (i.e. just concatenate the richText, write that to an attribute or display it) and still show a valid result. So it should be fine, if you just concat the richTexts and write them back to the object. If you want valid RTF then you would need to use richTextFragment, to cut off the header, BUT this will also cut away the font table. So to make a function that would give you a valid richText, you would need to create a new font table from the concatenated richTexts and translate the font statements in one of the richText. Total overkill, so I would suggest you stay with the concatenated richTexts.

There are several examples in the forum for concatenating richText. Use the search to find code examples. Hope this helps, regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Thank you Mathias!!

In fact the solution was strangely simple...Indeed i had just to concatenate the richtext extracted from the object text and put it in my new object. I think i had errors in manipulation between string and richtexts extracts. So i have just to do a thing like:

string s1 = richText o1."Object Text"
string s2 = richText o2."Object Text"
string s3 = richText s1 "\\par" s2
myNewObject."Object Text" richText s3

Thank you for your help!

Re: concatenate object Text with rtf
llandale - Wed Sep 12 14:10:59 EDT 2012

thomas.abdoul - Wed Sep 12 09:20:39 EDT 2012
Thank you Mathias!!

In fact the solution was strangely simple...Indeed i had just to concatenate the richtext extracted from the object text and put it in my new object. I think i had errors in manipulation between string and richtexts extracts. So i have just to do a thing like:

string s1 = richText o1."Object Text"
string s2 = richText o2."Object Text"
string s3 = richText s1 "\\par" s2
myNewObject."Object Text" richText s3

Thank you for your help!

  • use richTextWithOle() to get the entire contents.
  • Get out of the habit of concatenating large strings. Try this:
Buffer bufTemp = create()
bufTemp = richTextWithOle(o1."Object Text")
bufTemp += "\\par "
bufTemp += richTextWithOle(o2."Object Text")
myNewObject."Object Text" = richText(tempStringOf(bufTemp))
delete(bufTemp)

-Louie

Re: concatenate object Text with rtf
Mathias Mamsch - Wed Sep 12 17:17:01 EDT 2012

llandale - Wed Sep 12 14:10:59 EDT 2012

  • use richTextWithOle() to get the entire contents.
  • Get out of the habit of concatenating large strings. Try this:
Buffer bufTemp = create()
bufTemp = richTextWithOle(o1."Object Text")
bufTemp += "\\par "
bufTemp += richTextWithOle(o2."Object Text")
myNewObject."Object Text" = richText(tempStringOf(bufTemp))
delete(bufTemp)

-Louie

Lets do that right, shall we? ;-)
 

Buffer bufResult = create()
   Buffer bufTemp   = create() 
   bufResult = richTextWithOle(o1."Object Text")
   bufResult += "\\par "
   bufTemp = richTextWithOle(o2."Object Text")
   combine(bufResult, bufTemp, 0) 
   myNewObject."Object Text" = richText bufResult
   delete bufTemp
   delete bufResult

 


The += operator takes only strings, meaning you will have your big fat richTextWithOle going right to the string table. Also do not do the tempStringOf thing, because richText(string) also returns a big fat string for your string table. If you do it like above you will use RTF_buffer__ types, which (hopefully) come without string table pollutions. Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: concatenate object Text with rtf
llandale - Thu Sep 13 15:37:58 EDT 2012

Mathias Mamsch - Wed Sep 12 17:17:01 EDT 2012

Lets do that right, shall we? ;-)
 

Buffer bufResult = create()
   Buffer bufTemp   = create() 
   bufResult = richTextWithOle(o1."Object Text")
   bufResult += "\\par "
   bufTemp = richTextWithOle(o2."Object Text")
   combine(bufResult, bufTemp, 0) 
   myNewObject."Object Text" = richText bufResult
   delete bufTemp
   delete bufResult

 


The += operator takes only strings, meaning you will have your big fat richTextWithOle going right to the string table. Also do not do the tempStringOf thing, because richText(string) also returns a big fat string for your string table. If you do it like above you will use RTF_buffer__ types, which (hopefully) come without string table pollutions. Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

I was just testing you!

Re: concatenate object Text with rtf
Peter_Albert - Fri Sep 14 03:30:38 EDT 2012

Mathias Mamsch - Wed Sep 12 17:17:01 EDT 2012

Lets do that right, shall we? ;-)
 

Buffer bufResult = create()
   Buffer bufTemp   = create() 
   bufResult = richTextWithOle(o1."Object Text")
   bufResult += "\\par "
   bufTemp = richTextWithOle(o2."Object Text")
   combine(bufResult, bufTemp, 0) 
   myNewObject."Object Text" = richText bufResult
   delete bufTemp
   delete bufResult

 


The += operator takes only strings, meaning you will have your big fat richTextWithOle going right to the string table. Also do not do the tempStringOf thing, because richText(string) also returns a big fat string for your string table. If you do it like above you will use RTF_buffer__ types, which (hopefully) come without string table pollutions. Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

> The += operator takes only strings

Really? The DXL help lists three append operators for Buffers:

Buffer b += string s
Buffer b += char c
Buffer b += Buffer b

and so far I thought appending a Buffer would be safe, memory-wise. Is that not the case?

Cheers,

Peter

Re: concatenate object Text with rtf
Mathias Mamsch - Fri Sep 14 05:39:55 EDT 2012

Peter_Albert - Fri Sep 14 03:30:38 EDT 2012
> The += operator takes only strings

Really? The DXL help lists three append operators for Buffers:

Buffer b += string s
Buffer b += char c
Buffer b += Buffer b

and so far I thought appending a Buffer would be safe, memory-wise. Is that not the case?

Cheers,

Peter

Sorry I stand corrected. I just tested it and
 

#include <src/test/core/petools.inc>
#include <src/test/core/stringTable.inc>
 
print "Start of the program: \n"
printStringTable(); print "\n"
 
Buffer buf = create() 
Buffer buf2 = create() 
 
print "After Creating Buffers: \n"
printStringTable(); print "\n"
 
buf += "Hello"
 
print "After Adding a String using +=\n"
printStringTable(); print "\n"
 
buf2 = "World!"
buf += buf2
 
print "After Adding a Buffer using +=\n"
printStringTable(); print "\n"
 
buf2 = "ORLY?!"
buf2 += "YARLY!1"
buf += tempStringOf buf2
 
print "After Adding a Buffer using +=  tempStringOf\n"
printStringTable(); print "\n"
 
buf2 = "ZOMFG!"
buf2 += "WHUD?"
buf += stringOf buf2
print "After Adding a Buffer using +=  stringOf\n"
printStringTable(); print "\n"

 


The code above produces this output:

 

 

 

Start of the program: 
Count = 16732
Clashes = 2456
 
After Creating Buffers: 
Count = 16732
Clashes = 2456
 
After Adding a String using +=
Count = 16732
Clashes = 2456
 
After Adding a Buffer using +=
Count = 16732
Clashes = 2456
 
After Adding a Buffer using +=  tempStringOf
Count = 16732
Clashes = 2456
 
After Adding a Buffer using +=  stringOf
Count = 16733
Clashes = 2457



So neither Buffer += tempStringOf Buffer nor Buffer += Buffer produce a string table residual. If anyone is interested in the stringTable code, i can post that. Regards, Mathias



 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: concatenate object Text with rtf
Peter_Albert - Fri Sep 14 06:28:09 EDT 2012

Mathias Mamsch - Fri Sep 14 05:39:55 EDT 2012

Sorry I stand corrected. I just tested it and
 

#include <src/test/core/petools.inc>
#include <src/test/core/stringTable.inc>
 
print "Start of the program: \n"
printStringTable(); print "\n"
 
Buffer buf = create() 
Buffer buf2 = create() 
 
print "After Creating Buffers: \n"
printStringTable(); print "\n"
 
buf += "Hello"
 
print "After Adding a String using +=\n"
printStringTable(); print "\n"
 
buf2 = "World!"
buf += buf2
 
print "After Adding a Buffer using +=\n"
printStringTable(); print "\n"
 
buf2 = "ORLY?!"
buf2 += "YARLY!1"
buf += tempStringOf buf2
 
print "After Adding a Buffer using +=  tempStringOf\n"
printStringTable(); print "\n"
 
buf2 = "ZOMFG!"
buf2 += "WHUD?"
buf += stringOf buf2
print "After Adding a Buffer using +=  stringOf\n"
printStringTable(); print "\n"

 


The code above produces this output:

 

 

 

Start of the program: 
Count = 16732
Clashes = 2456
 
After Creating Buffers: 
Count = 16732
Clashes = 2456
 
After Adding a String using +=
Count = 16732
Clashes = 2456
 
After Adding a Buffer using +=
Count = 16732
Clashes = 2456
 
After Adding a Buffer using +=  tempStringOf
Count = 16732
Clashes = 2456
 
After Adding a Buffer using +=  stringOf
Count = 16733
Clashes = 2457



So neither Buffer += tempStringOf Buffer nor Buffer += Buffer produce a string table residual. If anyone is interested in the stringTable code, i can post that. Regards, Mathias



 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

> If anyone is interested in the stringTable code, i can post that

I am :-)

Re: concatenate object Text with rtf
Mathias Mamsch - Fri Sep 14 16:04:12 EDT 2012

Peter_Albert - Fri Sep 14 06:28:09 EDT 2012
> If anyone is interested in the stringTable code, i can post that

I am :-)

Well here you go: http://www.ibm.com/developerworks/forums/thread.jspa?threadID=455488&tstart=0

Have fun, Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: concatenate object Text with rtf
strathglass - Mon Mar 03 14:16:37 EST 2014

Mathias Mamsch - Wed Sep 12 17:17:01 EDT 2012

Lets do that right, shall we? ;-)
 

Buffer bufResult = create()
   Buffer bufTemp   = create() 
   bufResult = richTextWithOle(o1."Object Text")
   bufResult += "\\par "
   bufTemp = richTextWithOle(o2."Object Text")
   combine(bufResult, bufTemp, 0) 
   myNewObject."Object Text" = richText bufResult
   delete bufTemp
   delete bufResult

 


The += operator takes only strings, meaning you will have your big fat richTextWithOle going right to the string table. Also do not do the tempStringOf thing, because richText(string) also returns a big fat string for your string table. If you do it like above you will use RTF_buffer__ types, which (hopefully) come without string table pollutions. Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Coming back to this older thread...

I wanted to do something similar, but output rich text to the clipboard.

For some reason, it seems to loose the bullets from my objects (even when I explicitly tried adding "true,true" to end of setRichClip).

Other RTF formatting comes out OK (e.g. italics, bold, and indenting level).

Any ideas on how to fix? (I don't know anything about font tables, so the example code just uses something from a DXL help example.)

 

void appendOLEoTxt(Object o,Buffer b)
{
    Buffer bTmp=create()
        bTmp = richTextWithOle(o."Object Text")
        b += "\\par "
        combine(b,bTmp,0) 
        delete bTmp
}

Object o81=object(81,current Module)
Object o83=object(83,current Module)
Object o93=object(93,current Module)

Buffer bufResult = create()
bufResult = richTextWithOle(o81."Object Text")

appendOLEoTxt(o83,bufResult)
appendOLEoTxt(o93,bufResult)

string fontTable = "\\deff0{\\fonttbl {\\f1 Times New Roman;}}" 
setRichClip(bufResult,"Normal",fontTable)

delete bufResult